/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisgea.conexaobd;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConexaoBD {
	//public static Connection getConexao() throws Exception{
        public static Connection getConexao() throws Exception{
		Connection con;
		String login ="postgres";
                String senha = "postegres";
		//String senha ="1234";
                String nomeBanco = "bh";
		//String nomeBanco ="postgres";
		String driver ="org.postgresql.Driver";
                String servi = "logalhost";
		//com.mysql.jdbc.Driver
		final String url = "jdbc:postgresql://"+servi+":5432/"+nomeBanco;
		//"jbdc:mysql://localhost/"+nomeBanco;
		
                try {
			Class.forName(driver);
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("Classe do Driver não encontrado");
		}
		
		try {
			con=DriverManager.getConnection(url, login, senha);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new Exception("Falha ao Conectar ao Banco");
		}             
		return con;
	}


}
/**
 *
 * @author Usuario

public class ConexaoBD {
    private static Connection conn=null;
    public final static String DRIVER="com.mysql.jdbc.Driver";
    public final static String URL="jdbc:mysql://localhost:3306/bh";
    public final static String USER="root";
    public final static String PASSWD="root";
    
    private ConexaoBD(){
        if(conn == null)
            loadDriver();
    }
    private static void loadDriver(){
        try{
            Class.forName(DRIVER);
            conn=DriverManager.getConnection(URL, USER, PASSWD);
        }catch(Exception e){
            JOptionPane.showMessageDialog(null, "Falha de conexão");
        }
    }
    public static Connection getConnection(){
        if(conn==null)
            loadDriver();
        return conn;
    }
    public static void erroDB(){
        conn=null;
    }
}
*/